﻿$(document).ready(function () {
    var deletepopup;
    var Id;
    var Class;

    //удаление файла

    $(".deleteFile, .deleteFolder").click(function () {
        Id = $(this).attr('value');
        Class = $(this).attr('class');        
        
        deletepopup = $("#deletepopup").bPopup({

            easing: 'easeOutBack',
            speed: 500,
            transition: 'slideDown',
            onClose: function () {
                setTimeout(function () {
                    $('#deletediv span').remove();
                }, 300);
            }
        });;

        $('#deletediv div').append('<span>' + $(this).attr("name") + '</span>');

        

    });

    function deleteClick() {
        deletepopup.close();
        setTimeout(function () {            
            $('#deletediv span').remove();
        }, 300);
    }

    $('.cancel').click(deleteClick);


    //------------------------------------------------------------

    $(".ok").one('click',$('.ok'), ok);
   
    function ok () {
        if (Id != null) {
            var formData = new FormData();
            formData.append('fileId', Id);
            formData.append('cl', Class);        
            $.ajax({
                url: '/Delete/DeleteFile/',
                type: 'POST',
                data: formData,
                dataType: 'html',
                success: function () {
                    bool = false;
                    $.ajax({
                        url: '/Home/Index/' + $('.apriboxparentfolder').last().attr('id'),
                        dataType: 'html',
                        success: function (data) {                            
                            $('#main').html(data);
                        },
                        processData: false,
                        contentType: false,
                        cache: false
                    });
                },
                processData: false,
                contentType: false,
                cache: false
            });
            deleteClick();
        }
        
    }


    


});